import React, { FC } from 'react';
import { Form, Input, Button, Checkbox } from 'antd';
import { UserOutlined, LockOutlined } from '@ant-design/icons';
import * as styles from './style.less';
import { connect, Dispatch } from 'umi';
import _ from 'lodash';
interface ILoginProps {
  dispatch: Dispatch;
}
const Login: FC<ILoginProps> = ({ dispatch }) => {
  const onFinish = (value: any) => {
    console.log('Received values of form: ', value);
    dispatch({
      type: 'loginModel/getLogin',
      value: _.omit(value, ['remember']),
    });
  };
  return (
    <div className={styles.login}>
      <div className={styles.login_container}>
        <Form
          name="normal_login"
          className="login-form"
          initialValues={{ remember: true }}
          onFinish={onFinish}
        >
          <div style={{ fontSize: '18px', textAlign: 'center' }}>登录</div>
          <Form.Item
            name="username"
            rules={[
              {
                required: true,
                pattern: /^[a-zA-Z0-9_-]{4,16}$/,
                message: 'Please input your Username!',
              },
            ]}
          >
            <Input
              prefix={<UserOutlined className="site-form-item-icon" />}
              placeholder="Username"
            />
          </Form.Item>
          <Form.Item
            name="password"
            rules={[{ required: true, message: 'Please input your Password!' }]}
          >
            <Input
              prefix={<LockOutlined className="site-form-item-icon" />}
              type="password"
              placeholder="Password"
            />
          </Form.Item>
          <Form.Item>
            <Form.Item name="remember" valuePropName="checked" noStyle>
              <Checkbox>Remember me</Checkbox>
            </Form.Item>
          </Form.Item>

          <Form.Item>
            <Button
              type="primary"
              htmlType="submit"
              className="login-form-button"
            >
              Log in
            </Button>
          </Form.Item>
        </Form>
      </div>
    </div>
  );
};
export default connect()(Login);
